/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package me.tisoft.springphpview.viewresolver;

import com.googlecode.fcgi4j.FCGIConnection;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.View;

/**
 *
 * @author taleh
 */
public class PhpViewResolver extends org.springframework.web.servlet.view.AbstractCachingViewResolver {

    private java.util.Properties params;

    public void setParams(Properties params) {
        this.params = params;
    }

    @Override
    protected View loadView(String string, Locale locale) throws Exception {
        this.setCache(false);
        FCGIConnection connection = FCGIConnection.open();
        connection.connect(new InetSocketAddress(this.params.getProperty("server"), Integer.parseInt(this.params.getProperty("port"))));

        connection.beginRequest(this.params.getProperty("url"));
        connection.setRequestMethod("post");

        connection.addParams("DOCUMENT_ROOT", "/var/www");

            PhpFastcgiViewRenderer view = new PhpFastcgiViewRenderer(connection);
        return view;
    }
}
